package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.MiscellaneousReceiptDetail;
import com.pureut.storage.dto.MiscellaneousReceiptDetailDto;
import com.pureut.storage.dto.SubcontractReceiptDetailDto;
import com.pureut.storage.mapper.MiscellaneousReceiptDetailMapper;
import com.pureut.storage.service.MiscellaneousReceiptDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 *
 * Author:C
 * Date:2023/01/19 13:53
 * @DESC
 */
@Service
public class MiscellaneousReceiptDetailServiceImpl extends ServiceImpl<MiscellaneousReceiptDetailMapper, MiscellaneousReceiptDetail> implements MiscellaneousReceiptDetailService {

    @Resource
    MiscellaneousReceiptDetailMapper miscellaneousReceiptDetailMapper;

    /**
     * 其它入库明细列表
     * @param id
     * @return
     */
    @Override
    public List<MiscellaneousReceiptDetailDto> getMiscellaneousReceiptDetail(Long id) {
        List<MiscellaneousReceiptDetailDto> detailList = miscellaneousReceiptDetailMapper.getDetailList(id);
        //获取网型标准缓存字典数据
        List<SysDictData> netArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> netMap = netArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取铺网类型标准缓存字典数据
        List<SysDictData> netTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> netTypeMap = netTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //明细状态
        List<SysDictData> detailArray = DictUtils.getDictCache("miscellaneous_receipt_detail_status");
        Map<String, String> statusMap = detailArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (MiscellaneousReceiptDetailDto entity : detailList) {
            entity.setStatusDict(statusMap.get(entity.getStatus()));
            entity.setMaterialNetDict(netMap.get(entity.getMaterialNet()));
            entity.setMaterialNetTypeDict(netTypeMap.get(entity.getMaterialNetType()));
        }
        return detailList;
    }
}
